package com.wwl.net;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * 读取百度首页
 */
public class URLDemo {
    public static void main(String[] args) {
        try {
            URL url = new URL("http://www.baidu.com");
            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
            BufferedWriter bw = new BufferedWriter(new FileWriter("baidu_index.html"));
            String s;
            while((s=br.readLine())!=null){
                bw.write(s);
                //bw.newLine();

            }
            br.close();
            bw.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
